﻿/*
 * Autore: Artur Tolstenco
 */

using System;
using System.Globalization;
using System.Windows;
using RecipesManager.Data;

namespace RecipesManager.MainControls.RecipeSubControls
{
    /// <summary>
    /// Interaction logic for ViewOriginalRecipeWindow.xaml
    /// </summary>
    public partial class ViewOriginalRecipeWindow
    {
        IRecipe _currentRecipe;

        public ViewOriginalRecipeWindow()
        {
            InitializeComponent();

            bt_chiudi.IsCancel = true;
        }

        public IRecipe CurrentRecipe
        {
            internal get { return _currentRecipe; }
            set
            {
                if (value == null)
                    return;

                _currentRecipe = value;
                tb_title.Text = Application.Current.FindResource("ViewOriginalRecipeButtonTooltip") + " della ricetta " + _currentRecipe.Name;

                WriteOriginalRecipe();
            }
        }

        void WriteOriginalRecipe()
        {
            if (_currentRecipe == null)
                return;

            var str = "";

            str += "Nome ricetta: " + _currentRecipe.Name + Environment.NewLine;
            str += "Originale preso da: " + _currentRecipe.Source + Environment.NewLine;
            str += "Tempo di esecuzione: " + (_currentRecipe.OriginalPrepHours.HasValue ? _currentRecipe.OriginalPrepHours.Value.ToString(CultureInfo.InvariantCulture) : "??") + " ore e " +
                   (_currentRecipe.OriginalPrepMinutes.HasValue ? _currentRecipe.OriginalPrepMinutes.Value.ToString(CultureInfo.InvariantCulture) : "??") + " minuti" + Environment.NewLine;
            str += "Numero porzioni: " + _currentRecipe.OriginalServings + Environment.NewLine;
            str += "Famiglia unità di misura: " + RecipeMainPane.GetMeasureFamilyString(_currentRecipe.MeasureFamily) +
                   Environment.NewLine;

            str += Environment.NewLine;
            str += "Lista ingredienti:" + Environment.NewLine;

            foreach (var i in _currentRecipe.OriginalIngredients)
                str += "Nome ingrediente: " + i.Name + "; Note: " + i.Notes + "; Quantità: " + i.Quantity + " " +
                       i.Measure.ShortName + ";" + Environment.NewLine;


            str += Environment.NewLine;
            str += "Lista passi:" + Environment.NewLine;

            foreach (var s in _currentRecipe.OriginalSteps)
            {
                if (s.Type == StepType.Generic)
                    str += "Descrizione: " + s.Description + "; Risorse occupate: " + s.Resources + "; ";
                else
                    str += "Esegui sottoricetta " + s.SubRecipe.Name + " per " + s.Servings + " porzioni; ";

                str += "Tempo di esecuzione: " + (s.StepHours.HasValue ? s.StepHours.Value.ToString(CultureInfo.InvariantCulture) : "??") + " ore e " + (s.StepMinutes.HasValue ? s.StepMinutes.Value.ToString(CultureInfo.InvariantCulture) : "??") + " minuti" + Environment.NewLine;
            }

            tb_description.Text = str;

        }

        private void Bt_Chiudi_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }
    }
}
